package com.fortune.common.spring.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.fortune.common.redis.RedisClient;
import com.fortune.constants.redis.CacheKeys;

public class WechatLoginiInterceptor extends HandlerInterceptorAdapter {
	@Autowired
	private RedisClient redisClient;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String token = request.getHeader("Authorization");
		String idString = redisClient.get(CacheKeys.SALES_MAN_LOGIN_TOKEN, token);
		if (idString==null) {
			request.getRequestDispatcher("/error/login").forward(request, response);
			return false;
		}
		return true;
	}
	
}
